home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Graphic Gems I, II & III (C_C++) / Graphics Gems C Code.sea / GemsIII / accurate_scan / exhaust.c < prev    next >
C/C++ Source or Header  |  1992-06-16  |  4KB  |  182 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <starbase.c.h>
  5.  
  6. #include "fixpoint.h"
  7.  
  8. extern void printnbits();
  9. extern void subpixel_triangle(fixpoint x0, fixpoint y0,
  10.                               fixpoint x1, fixpoint y1,
  11.                               fixpoint x2, fixpoint y2);
  12. extern void triangle(int x0, int y0, int x1, int y1, int x2, int y2);
  13.  
  14.  
  15. /*
  16.   Exhaustively test all cases of (subpixel) triangle drawing.
  17.  
  18.   In fixpoint.h, Set HIBITS, LOBITS to small values (like 5, 2) to run this,
  19.   or you'll wait forever and run out of memory.
  20.  
  21.   */
  22.  
  23. static int fildes;
  24. static struct color {float r, g, b;};
  25. int verbose = 0;
  26.  
  27. #define SIZE 200
  28. #define NPIXELS (1 << (HIBITS - 2))
  29. #define BUFSIZE NPIXELS
  30. int buffer[BUFSIZE][BUFSIZE];
  31.  
  32. void clear_buffer()
  33. {
  34.   register int i, j;
  35.   for(i=0; i<BUFSIZE; i++)
  36.      for(j=0; j<BUFSIZE; j++)
  37.         buffer[i][j] = 0;
  38. }
  39.  
  40. /* Check if test succeeded (ie. buffer is full of ones,
  41.     except for first line/column).
  42. */
  43. void buffer_check()
  44. {
  45.   register int i, j;
  46.   int broken = 0;
  47.  
  48.   for(i=1; i<BUFSIZE; i++)
  49.      for(j=1; j<BUFSIZE; j++)
  50.         if (buffer[i][j] != 1) {
  51.           printf("ERROR: Buffer[%d][%d] = %d, not 1!!!\n",
  52.                     i, j, buffer[i][j]);
  53.           broken = 1;
  54.           break;
  55.         }
  56.  
  57.   if (broken) {
  58.      for(j=1; j<BUFSIZE; j++) {
  59.         for(i=1; i<BUFSIZE; i++) {
  60.           printf("%c", buffer[i][j] ? 'o' : '.' );
  61.         }
  62.         printf("\n");
  63.      }
  64.   }
  65. }
  66.  
  67.  
  68. int xoff = 100;
  69. int yoff = 100;
  70.  
  71. void
  72. draw_point (int ix, int iy)
  73. {
  74.  
  75.   if ((ix >= BUFSIZE) || (iy >= BUFSIZE)) {
  76.       printf("ERROR: ix (%d) or iy (%d) >= BUFSIZE (%d)\n", ix, iy, BUFSIZE);
  77.       abort();
  78.     }
  79.  
  80.   if (buffer[ix][iy]){
  81.      printf("OOPS -- repainting pixel (%d, %d)\n", ix, iy);
  82.  
  83.      fill_color(fildes, 1.0, 0.0, 0.5);
  84.      intrectangle(fildes, xoff + ix, yoff + iy, xoff + ix+1, yoff + iy+1);
  85.      fill_color(fildes, 1.0, 1.0, 1.0);
  86.  
  87.      buffer[ix][iy] = 0;
  88.  
  89.      make_picture_current(fildes);
  90.      abort();
  91.   }
  92.   else {
  93.      buffer[ix][iy] = 1;
  94.      intrectangle(fildes, xoff + ix, yoff + iy, xoff + ix+1, yoff + iy+1);
  95.   }
  96. }
  97.  
  98.  
  99. int
  100. InitScreen()
  101. {
  102.     char    *sb_dev, *driver;
  103.     
  104.     printnbits();
  105.  
  106.     sb_dev = getenv("SB_OUTDEV");   
  107.     if(!sb_dev) sb_dev = getenv("OUTDEV");   
  108.     if(!sb_dev) sb_dev = "/dev/crt1";
  109.  
  110.     driver = getenv("SB_OUTDRIVER");
  111.     if(!driver) driver = getenv("OUTDRIVER");
  112.     if (!driver ) driver = "hp98731";
  113.     
  114.     fildes = gopen(sb_dev,OUTDEV,driver,INIT|INT_XFORM);
  115.     interior_style(fildes,INT_SOLID,FALSE);
  116.     
  117.     intvdc_extent(fildes,0,0,SIZE, SIZE);
  118.     mapping_mode(fildes,FALSE);
  119.     
  120.     drawing_mode(fildes,6);      /* xor mode */
  121.     
  122.     clear_control(fildes, CLEAR_VIEWPORT);
  123.     fill_color(fildes, 1.0, 1.0, 1.0);
  124.     
  125.     return(fildes);
  126. }
  127.  
  128.  
  129. void
  130. main()
  131. {
  132.   int i, j;
  133.   int nsubpixels = 1 << (HIBITS+LOBITS);
  134.   fixpoint zero, maxpix;
  135.  
  136.   zero = 0;
  137.   maxpix = ((NPIXELS-1) << LOBITS) | LOMASK;
  138.  
  139.   InitScreen();
  140.  
  141.   if (verbose) {
  142.      printf("zero "); fp_print(zero); printf(", max "); fp_print(maxpix);
  143.      printf("\n");
  144.   }
  145.  
  146.   for (i=0; i != maxpix + 1; i++) {
  147.      for (j=0; j != maxpix + 1; j++) {
  148.  
  149.         if (verbose) {
  150.           printf("\n\n************** New Iteration ************\n\n");
  151.           printf("%3d, %3d --> ", i, j);
  152.           fp_print(i); printf(", "); fp_print(j); printf("\n");
  153.         }
  154.  
  155.         clear_buffer();
  156.         clear_view_surface(fildes); 
  157.  
  158.         fill_color(fildes, 0.5, 0.5, 0.5);
  159.         subpixel_triangle(zero, zero,  zero,  maxpix, i, j);
  160.  
  161.         fill_color(fildes, 0.0, 1.0, 0.0);
  162.         subpixel_triangle(zero, zero,  maxpix,  zero, i, j);
  163.  
  164.         fill_color(fildes, 0.0, 0.0, 1.0);
  165.         subpixel_triangle(zero,  maxpix,  maxpix,   maxpix, i, j);
  166.  
  167.         fill_color(fildes, 1.0, 0.0, 0.0);
  168.         subpixel_triangle( maxpix, zero,  maxpix,   maxpix, i, j);
  169.  
  170.         buffer_check();
  171.         make_picture_current(fildes);
  172.  
  173.         if (verbose) {
  174.           printf("  hit <return> for next iteration\n");
  175.           getchar();
  176.         }
  177.  
  178.      }
  179.   }
  180. }
  181.  
  182.